import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
  selector: 'app-delete-data',
  templateUrl: './delete-data.component.html',
  styleUrls: ['./delete-data.component.css'],
})
export class DeleteDataComponent implements OnInit {
  visible = false;

  one = '';
  range = {
    first: '',
    second: '',
  };

  @Input() list: any;
  @Output() result = new EventEmitter();

  constructor(private message: NzMessageService) {}

  ngOnInit(): void {}
  open(): void {
    this.visible = true;
  }

  close(): void {
    this.visible = false;
  }

  onDeleteOne() {
    if (Number(this.one) >= 0 && this.list.length >= Number(this.one)) {
      this.result.emit(Number(this.one));
      this.message.success('删除成功')
      this.close();
    } else {
      this.message.error('输入值超出表格范围')
    }
  }

  onDeleteRange() {
    if(Number(this.range.first) >=0 && Number(this.range.second) >=0){
      if(this.list.length > Number(this.range.first)) {
        if(this.list.length > Number(this.range.second)) {
          if(Number(this.range.first) <= Number(this.range.second)){
            this.result.emit(this.range);
            this.message.success('删除成功')
            this.close();
          }else{
            this.message.error('开始行号超过结束行号')
          }
        }else{
          this.message.error('结束行号超出表格范围')
        }
      }else{
        this.message.error('开始行号超出表格范围')
      }
    }else{
      this.message.error('请输入正确的范围')
    }
  }
}
